import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { DeptService } from "@service/system/dept.service";
import { ListDeptDTO, CreateDeptDTO, UpdateDeptDTO } from "@dto/system/dept.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/system/dept')
export class PostController {
  @Inject()
  deptService: DeptService;

  // 获取列表
  @Auth('system:dept:list')
  @Get('/list')
  async list(@Query() queryParams: ListDeptDTO) {
    return await this.deptService.list(queryParams);
  }

  // 新增
  @Auth('system:dept:add')
  @Log({ title: '部门管理', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() dept: CreateDeptDTO) {
    return await this.deptService.create(dept);
  }

  // 删除
  @Auth('system:dept:remove')
  @Log({ title: '部门管理', businessType: BusinessType.REMOVE })
  @Del('/:deptId')
  async delete(@Param('deptId') deptId: number) {
    return await this.deptService.delete(deptId);
  }

  // 修改
  @Auth('system:dept:edit')
  @Log({ title: '部门管理', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() dept: UpdateDeptDTO) {
    return await this.deptService.update(dept);
  }

  // 获取详情
  @Auth('system:dept:query')
  @Get('/:deptId')
  async get(@Param('deptId') deptId: number) {
    return await this.deptService.detail(deptId);
  }

  // 排除子节点，点击部门详情时获取 弹框选择上级部门时使用，需要排除子节点
  @Get('/list/exclude/:deptId')
  async excludeChild() {
    return this.deptService.excludeChild();
  }
}
